<template>
  <view class="tab-bar">
    <view v-for="(item, index) in list" :key="index" class="tab-bar-item" @click="switchTab(item, index)">
      <image class="tab_img" :src="currentIndex === index ? item.selectedIconPath : item.iconPath"></image>
      <view class="tab_text" :style="{ color: currentIndex === index ? selectedColor : color }">{{ item.text }}</view>
    </view>
  </view>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { defineProps } from 'vue';
import { useTokenStore } from '../../store/token';
const props = defineProps({
  selectedIndex: {
    type: Number,
    default: 0
  }
});
const color = ref("red");
const selectedColor = ref("red");
const list = ref([]);
const currentIndex = ref(props.selectedIndex);

onMounted(() => {
  if (uni.getStorageSync('usname') === 'admin') {
    
    list.value = [
      {
        pagePath:'../../../pages/supplier/wjk/catetory',
        text: "首页",
        iconPath: "../../static/tabs/main1.png",
        selectedIconPath: "../../static/tabs/main2.png"
      },
      {
        pagePath: "../../../pages/supplier/bill/bill",
        text: "账单",
        iconPath: "../../static/tabs/dd1.png",
        selectedIconPath: "../../static/tabs/dd2.png"
      },
      {
        pagePath: "../../../pages/supplier/djshenhe/shenhe",
        text: "审核",
        iconPath: "../../static/tabs/fl1.png",
        selectedIconPath: "../../static/tabs/fl2.png"
      },
      {
        pagePath: "../../../pages/supplier/my/my",
        text: "我的",
        iconPath: "../../static/wo.png",
        selectedIconPath: "../../static/wo1.png"
      }
    ];
  } else {
    // 医管
    list.value = [
      {
        pagePath: "../../../pages/businessman/fenlei/fenlei",
        text: "首页",
        iconPath: "../../static/shou.png",
        selectedIconPath: "../../static/shou1.png"
      },
      {
        pagePath: "../../../pages/businessman/shopcar/shopcar",
        text: "鲸肚",
        iconPath: "../../static/tabs/jd1.png",
        selectedIconPath: "../../static/tabs/jd2.png"
      },
      {
        pagePath: "../../../pages/businessman/index/admin",
        text: "我的",
        iconPath: "../../static/wo.png",
        selectedIconPath: "../../static/wo1.png"
      }
    ];
  }

  // 打印路径以便调试
  // list.value.forEach((item, index) => {
  //   console.log(`Item ${index}:`, item.iconPath, item.selectedIconPath);
  // });
});

const switchTab = (item, index) => {
  currentIndex.value = index;
  let url = item.pagePath;
  uni.redirectTo({
    url: url
  });
};
</script>

<style lang="scss">
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 120rpx;
  background: white;
  display: flex;
  justify-content: center;
  align-items: center;
  padding-bottom: env(safe-area-inset-bottom); // 适配iPhone X的底部

  .tab-bar-item {
    flex: 1;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;

    .tab_img {
      width: 60rpx;
      height: 60rpx;
    }

    .tab_text {
      font-size: 28rpx;
      margin-top: 9rpx;
    }
  }
}
</style>